package com.battle.service.service.impl;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.battle.pojo.entity.*;
import com.battle.pojo.enums.StudyStatusEnum;
import com.battle.pojo.excel.OrganizationTreeListExcel;
import com.battle.pojo.param.caseBaseInfo.CaseStatisticsParam;
import com.battle.pojo.param.caseBaseInfo.GetCaseDiscountingParam;
import com.battle.pojo.param.personWarCase.*;
import com.battle.pojo.vo.caseBaseInfo.CaseCakeDetailsVo;
import com.battle.pojo.vo.caseBaseInfo.CaseDiscountingDetailsVo;
import com.battle.pojo.vo.caseBaseInfo.CaseDiscountingVo;
import com.battle.pojo.vo.personWarCase.*;
import com.battle.pojo.dto.personWarCase.*;
import com.battle.service.mapper.UserMapper;
import com.battle.service.repository.in.*;
import com.battle.service.service.in.PersonWarCaseService;
import com.battle.service.service.in.UserOrganizationMpService;
import com.battle.service.service.in.UserService;
import com.battle.service.utils.ExcelUtils;
import com.battle.service.utils.StringPassUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.exceptions.BizException;
import nirvana.core.utils.ids.IdGenerator;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;


import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 【描 述】：人员战力表服务
 * 【环 境】：J2SE 17
 * 【详 细】：
 */
@Service
@AllArgsConstructor
public class PersonWarCaseServiceImpl implements PersonWarCaseService {

    private final PersonWarCaseRepository personWarCaseRepository;
    private final PersonMpWarCaseRepository mpWarCaseRepository;
    private final OrganizationRepository organizationRepository;
    private final TeamWarCaseRepository teamWarCaseRepository;
    private final CarWarCaseRepository carWarCaseRepository;
    private final TrainingPersonSettingRepository personSettingRepository;
    private final PersonOrganizationMpRepository personOrganizationMpRepository;
    private final UserRepository userRepository;

    /**
     * 创建人员战力表
     *
     * @param param
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long createPersonWarCase(CreatePersonWarCaseParam param) {
        PersonWarCase personWarCase = new PersonWarCase();
        BeanUtils.copyProperties(param, personWarCase);
        Long id = IdGenerator.SNOW.generate();
        personWarCase.setId(id);

        //随机生成60-100之间的数字
        personWarCase.setCombatPower((int) (Math.random() * 40 + 60));
        personWarCaseRepository.create(personWarCase);

        PersonOrganizationMp mp=new PersonOrganizationMp();
        mp.setId(IdGenerator.SNOW.generate());
        mp.setPersonId(id);
        mp.setOrganizationId(param.getOrganizationId());
        personOrganizationMpRepository.save(mp);
        return id;
    }

    /**
     * 修改人员战力表
     *
     * @param param
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void editPersonWarCase(EditPersonWarCaseParam param) {
        Long id = param.getId();
        PersonWarCase personWarCase = personWarCaseRepository.getByIdCheck(id);
        BeanUtils.copyProperties(param, personWarCase);
        personWarCaseRepository.edit(personWarCase);

        PersonOrganizationMp mp=new PersonOrganizationMp();
        mp.setPersonId(id);
        List<PersonOrganizationMp> listByEntity = personOrganizationMpRepository.getListByEntity(mp);
        if (CollectionUtil.isNotEmpty(listByEntity)){
            List<Long> ids = listByEntity.stream().map(PersonOrganizationMp::getId).distinct().collect(Collectors.toList());
            personOrganizationMpRepository.removeByIds(ids);
        }

        mp=new PersonOrganizationMp();
        mp.setId(IdGenerator.SNOW.generate());
        mp.setPersonId(id);
        mp.setOrganizationId(param.getOrganizationId());
        personOrganizationMpRepository.save(mp);
    }

    /**
     * 移除人员战力表
     *
     * @param id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removePersonWarCase(Long id) {
        personWarCaseRepository.removeById(id);
        mpWarCaseRepository.removeByPersonId(id);
    }

    /**
     * 启动/禁用人员战力表
     *
     * @param id
     */
    @Override
    public void enabledPersonWarCase(Long id) {
        PersonWarCase personWarCase = personWarCaseRepository.getByIdCheck(id);
        personWarCase.setIsDisable(!personWarCase.getIsDisable());
        personWarCaseRepository.edit(personWarCase);
    }

    /**
     * 获取人员战力表详情
     *
     * @param id
     * @return
     */
    @Override
    public GetPersonWarCaseVo getPersonWarCase(Long id) {
        PersonWarCase personWarCase = personWarCaseRepository.getByIdCheck(id);
        GetPersonWarCaseVo vo = new GetPersonWarCaseVo();
        BeanUtils.copyProperties(personWarCase, vo);
        return vo;
    }

    /**
     * 获取人员战力表 列表
     *
     * @param param
     * @return
     */
    @Override
    public PageResult<GetPersonWarCaseListVo> getPersonWarCaseList(GetPersonWarCaseListParam param) {

        SelectPersonWarCaseDto dto = new SelectPersonWarCaseDto();
        BeanUtils.copyProperties(param, dto);
        if (param.getOrganizationId() != null) {
            List<Long> ids = organizationRepository.getOrganizationIdList(param.getOrganizationId());
            dto.setIds(ids);
        }
        if (param.getOrderBy() != null) {
            dto.setOrderBy(StringPassUtil.convertToSnakeCase(param.getOrderBy()));
        }
        Page<PersonWarCase> page = personWarCaseRepository.selectPersonWarCase(dto);
        List<PersonWarCase> personWarCaseList = page.getRecords();
        List<GetPersonWarCaseListVo> list = new ArrayList<>();
        for (PersonWarCase personWarCase : personWarCaseList) {
            GetPersonWarCaseListVo vo = new GetPersonWarCaseListVo();
            BeanUtils.copyProperties(personWarCase, vo);

            //多组织架构名称
            List<PersonOrganizationMp> personOrganizationMps = personOrganizationMpRepository.selectByOrganizationId(null, personWarCase.getId());
            if (CollectionUtil.isNotEmpty(personOrganizationMps)) {
                List<Long> organizationIds = personOrganizationMps.stream().map(PersonOrganizationMp::getOrganizationId).collect(Collectors.toList());
                List<Organization> organizationList = organizationRepository.listByIds(organizationIds);
                if (CollectionUtil.isNotEmpty(organizationList)) {
                    vo.setOrganizationName(organizationList.stream().map(Organization::getName).collect(Collectors.joining(",")));
                }
            }
            list.add(vo);
        }
        return new PageResult<>(list, page);

    }

    @Override
    public void exportPersonWarCaseList(GetPersonWarCaseListParam param, HttpServletResponse response) throws IOException {
        param.setSize(Long.MAX_VALUE);
        PageResult<GetPersonWarCaseListVo> pageResult = getPersonWarCaseList(param);
        List<GetPersonWarCaseListVo> list = pageResult.getRecords();
        ExcelUtils.exportExcel(list, "人员战力", "人员战力", GetPersonWarCaseListVo.class, "人员战力",response);
    }

    /**
     * 获取人员战力表下拉列表
     *
     * @param param
     * @return
     */
    @Override
    public List<GetPersonWarCaseDownListVo> getPersonWarCaseDownList(GetPersonWarCaseDownListParam param) {
        List<GetPersonWarCaseDownListVo> list = new ArrayList<>();
        //修改多组织架构
        List<PersonOrganizationMp> personOrganizationMps = personOrganizationMpRepository.selectByOrganizationId(param.getOrganizationId(), null);
        List<Long> personIds = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(personOrganizationMps)) {
            personIds = personOrganizationMps.stream().map(PersonOrganizationMp::getPersonId).collect(Collectors.toList());
        }
        if (CollectionUtil.isNotEmpty(personIds)){
            List<PersonWarCase> personWarCaseList = personWarCaseRepository.listByIds(personIds);
            for (PersonWarCase personWarCase : personWarCaseList) {
                GetPersonWarCaseDownListVo vo = new GetPersonWarCaseDownListVo();
                BeanUtils.copyProperties(personWarCase, vo);
                list.add(vo);
            }
        }

        return list;
    }

    /**
     * 获取组织架构下需要考试的人员列表
     *
     * @param param
     * @return
     */
    @Override
    public List<GetPersonWarCaseDownListVo> getPersonTrainingList(GetPersonTrainingListParam param) {
        //获取该组织架构下的用户
        List<PersonOrganizationMp> personOrganizationMps = personOrganizationMpRepository.selectByOrganizationId(param.getOrganizationId(), null);
        if (CollectionUtil.isEmpty(personOrganizationMps)) {
            return new ArrayList<>();
        }
        List<Long> personIds = personOrganizationMps.stream().map(PersonOrganizationMp::getPersonId).collect(Collectors.toList());
        List<PersonWarCase> personWarCaseList = personWarCaseRepository.getBaseMapper().selectList(new LambdaQueryWrapper<PersonWarCase>()
                .in(PersonWarCase::getId, personIds)
                .eq(PersonWarCase::getIsDelete, false));
        if (CollectionUtil.isEmpty(personWarCaseList)) {
            return new ArrayList<>();
        }

        //获取该组织架构下不需要考试的人员
        List<TrainingPersonSetting> personSettingList = personSettingRepository.getBaseMapper().selectList(
                new LambdaQueryWrapper<>(TrainingPersonSetting.class)
                        .eq(TrainingPersonSetting::getDepartmentId, param.getOrganizationId())
                        .eq(TrainingPersonSetting::getIsDelete, false)
        );

        List<Long> personSettingIds = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(personSettingList)) {
            personSettingIds = personSettingList.stream().map(TrainingPersonSetting::getUserId).collect(Collectors.toList());
        }
        //再添加上选择的缺训人员
        if (CollectionUtil.isNotEmpty(param.getPersonIds())) {
            personSettingIds.addAll(param.getPersonIds());
        }

        List<GetPersonWarCaseDownListVo> list = new ArrayList<>();
        //需要考试的人员=该组织架构下所有的用户-不需要考试的用户
        if (CollectionUtil.isNotEmpty(personWarCaseList)) {
            for (PersonWarCase personWarCase : personWarCaseList) {
                if (!personSettingIds.contains(personWarCase.getId())) {
                    GetPersonWarCaseDownListVo vo = new GetPersonWarCaseDownListVo();
                    BeanUtils.copyProperties(personWarCase, vo);
                    list.add(vo);
                }
            }
        }
        return list;
    }

    /**
     * 根据评估参数重新计算人员指数和队伍指数，还有车辆指数
     */
    @Override
    public void updateCombatPower() {
        List<PersonWarCase> personWarCaseList = personWarCaseRepository.list();
        List<CarWarCase> carWarCaseList = carWarCaseRepository.list();
        List<TeamWarCase> teamWarCaseList = teamWarCaseRepository.list();

        //人员
        if (CollectionUtil.isNotEmpty(personWarCaseList)) {
            for (PersonWarCase personWarCase : personWarCaseList) {
                personWarCase.setCombatPower((int) (Math.random() * 40 + 60));
            }
            personWarCaseRepository.updateBatchById(personWarCaseList);
        }

        //车辆
        if (CollectionUtil.isNotEmpty(carWarCaseList)) {
            for (CarWarCase personWarCase : carWarCaseList) {
                personWarCase.setCombatPower((int) (Math.random() * 40 + 60));
            }
            carWarCaseRepository.updateBatchById(carWarCaseList);
        }

        //队伍
        if (CollectionUtil.isNotEmpty(teamWarCaseList)) {
            for (TeamWarCase personWarCase : teamWarCaseList) {
                personWarCase.setCombatPower((int) (Math.random() * 40 + 60));
            }
            teamWarCaseRepository.updateBatchById(teamWarCaseList);
        }
    }

    /**
     * 获取人员报告url
     *
     * @param id
     * @return
     */
    @Override
    public String getReportUrl(Long id) {
        PersonWarCase personWarCase = personWarCaseRepository.getByIdCheck(id);

        //多组织架构名称
        String organizationName = "";
        List<PersonOrganizationMp> personOrganizationMps = personOrganizationMpRepository.selectByOrganizationId(null, id);
        if (CollectionUtil.isNotEmpty(personOrganizationMps)) {
            List<Long> organizationIds = personOrganizationMps.stream().map(PersonOrganizationMp::getOrganizationId).collect(Collectors.toList());
            List<Organization> organizationList = organizationRepository.listByIds(organizationIds);
            if (CollectionUtil.isNotEmpty(organizationList)) {
                organizationName = organizationList.stream().map(Organization::getName).collect(Collectors.joining(","));
            }
        }

        String url = "http://139.196.201.143:13006/generate/test/word";
        String userName = personWarCase.getName();
        String job =organizationName;

        String name = userName + job + LocalDateTime.now();
        JSONObject all = new JSONObject();
        all.put("fileName", name + ".docx");
        all.put("job", job);
        all.put("userName", userName);

        String result = HttpUtil.createPost(url)
                .body(all.toString()).execute().body();

        JSONObject jsonObject = JSONUtil.parseObj(result);
        if (jsonObject != null) {
            return jsonObject.getStr("url");
        }
        return "";
    }

    /**
     * 战例统计折线图
     *
     * @return
     */
    @Override
    public CaseDiscountingVo getWarCaseNumber(GetCaseDiscountingParam param) {
        CaseDiscountingVo vo = new CaseDiscountingVo();
        //时间区间有多少个月份
        List<String> xData = getBetweenMonth(param.getStartTime(), param.getEndTime());
        if (CollectionUtil.isEmpty(xData)) return vo;

        List<CaseDiscountingDetailsVo> itemList = new ArrayList<>();

        //人员战力
        CaseDiscountingDetailsVo caseVo = new CaseDiscountingDetailsVo();
        List<BigDecimal> caseValueList = new ArrayList<>();
        caseVo.setName("人员战力指数");
        List<CaseCakeDetailsVo> caseTimeVoList = personWarCaseRepository.getPersonCaseTimeVoList(param.getStartTime(), param.getEndTime());
        Map<String, CaseCakeDetailsVo> caseTimeVoListMp = new HashMap<>();
        if (CollectionUtil.isNotEmpty(caseTimeVoList)) {
            caseTimeVoListMp = caseTimeVoList.stream().collect(Collectors.toMap(CaseCakeDetailsVo::getName, v -> v));
        }
        for (String xDatum : xData) {
            CaseCakeDetailsVo caseCakeDetailsVo = caseTimeVoListMp.get(xDatum);
            if (caseCakeDetailsVo != null) {
                caseValueList.add(caseCakeDetailsVo.getNumber());
            } else {
                caseValueList.add(BigDecimal.ZERO);
            }
        }
        caseVo.setValueList(caseValueList);
        itemList.add(caseVo);

        //队伍战力
        caseVo = new CaseDiscountingDetailsVo();
        caseValueList = new ArrayList<>();
        caseVo.setName("队伍战力指数");
        caseTimeVoList = personWarCaseRepository.getTeamCaseTimeVoList(param.getStartTime(), param.getEndTime());
        caseTimeVoListMp = new HashMap<>();
        if (CollectionUtil.isNotEmpty(caseTimeVoList)) {
            caseTimeVoListMp = caseTimeVoList.stream().collect(Collectors.toMap(CaseCakeDetailsVo::getName, v -> v));
        }
        for (String xDatum : xData) {
            CaseCakeDetailsVo caseCakeDetailsVo = caseTimeVoListMp.get(xDatum);
            if (caseCakeDetailsVo != null) {
                caseValueList.add(caseCakeDetailsVo.getNumber());
            } else {
                caseValueList.add(BigDecimal.ZERO);
            }
        }
        caseVo.setValueList(caseValueList);
        itemList.add(caseVo);

        //车辆战力
        caseVo = new CaseDiscountingDetailsVo();
        caseValueList = new ArrayList<>();
        caseVo.setName("车辆战力指数");
        caseTimeVoList = personWarCaseRepository.getCarCaseTimeVoList(param.getStartTime(), param.getEndTime());
        caseTimeVoListMp = new HashMap<>();
        if (CollectionUtil.isNotEmpty(caseTimeVoList)) {
            caseTimeVoListMp = caseTimeVoList.stream().collect(Collectors.toMap(CaseCakeDetailsVo::getName, v -> v));
        }
        for (String xDatum : xData) {
            CaseCakeDetailsVo caseCakeDetailsVo = caseTimeVoListMp.get(xDatum);
            if (caseCakeDetailsVo != null) {
                caseValueList.add(caseCakeDetailsVo.getNumber());
            } else {
                caseValueList.add(BigDecimal.ZERO);
            }
        }
        caseVo.setValueList(caseValueList);
        itemList.add(caseVo);

        vo.setXData(xData);
        vo.setItemList(itemList);
        return vo;
    }

    /**
     * 根据类型获取战例统计饼图 0：人员 1：车辆 2：队伍
     *
     * @param param
     * @return
     */
    @Override
    public List<GetPersonWarCaseDetailsVo> getWarCaseDetailsNumber(CaseStatisticsParam param) {
        List<GetPersonWarCaseDetailsVo> voList = new ArrayList<>();

        switch (param.getType()) {
            case 0:
                //人员战力
                GetPersonWarCaseDetailsVo vo = new GetPersonWarCaseDetailsVo();
                vo.setName("60分及以下");
                Integer number = personWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<PersonWarCase>()
                        .between(PersonWarCase::getCombatPower, 0, 60).eq(PersonWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);

                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("60-70分");
                number = personWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<PersonWarCase>()
                        .between(PersonWarCase::getCombatPower, 61, 70).eq(PersonWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);

                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("70-80分");
                number = personWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<PersonWarCase>()
                        .between(PersonWarCase::getCombatPower, 71, 80).eq(PersonWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);

                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("80-100分");
                number = personWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<PersonWarCase>()
                        .between(PersonWarCase::getCombatPower, 81, 100).eq(PersonWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);
                break;
            case 1:
                //车辆战力
                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("60分及以下");
                number = carWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<CarWarCase>()
                        .between(CarWarCase::getCombatPower, 0, 60).eq(CarWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);

                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("60-70分");
                number = carWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<CarWarCase>()
                        .between(CarWarCase::getCombatPower, 61, 70).eq(CarWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);

                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("70-80分");
                number = carWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<CarWarCase>()
                        .between(CarWarCase::getCombatPower, 71, 80).eq(CarWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);

                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("80-100分");
                number = carWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<CarWarCase>()
                        .between(CarWarCase::getCombatPower, 81, 100).eq(CarWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);
                break;
            case 2:
                //队伍战力
                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("60分及以下");
                number = teamWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<TeamWarCase>()
                        .between(TeamWarCase::getCombatPower, 0, 60).eq(TeamWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);

                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("60-70分");
                number = teamWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<TeamWarCase>()
                        .between(TeamWarCase::getCombatPower, 61, 70).eq(TeamWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);

                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("70-80分");
                number = teamWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<TeamWarCase>()
                        .between(TeamWarCase::getCombatPower, 71, 80).eq(TeamWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);

                vo = new GetPersonWarCaseDetailsVo();
                vo.setName("80-100分");
                number = teamWarCaseRepository.getBaseMapper().selectCount(new LambdaQueryWrapper<TeamWarCase>()
                        .between(TeamWarCase::getCombatPower, 81, 100).eq(TeamWarCase::getIsDelete, false)).intValue();
                vo.setValue(number);
                voList.add(vo);
                break;
            default:
                break;
        }
        return voList;
    }

    /**
     * 导入人员战力表
     *
     * @param file
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importPersonWarCase(MultipartFile file) {
        StringBuffer error = new StringBuffer();
        try {
            ImportParams params = new ImportParams();
            params.setTitleRows(0);
            params.setStartRows(0);
            List<ImportPersonWarCaseParam> result = ExcelImportUtil.importExcel(file.getInputStream(), ImportPersonWarCaseParam.class, params);
            if (CollectionUtil.isNotEmpty(result)) {
                for (ImportPersonWarCaseParam importPersonWarCaseParam : result) {
                    //检查组织是否存在
                    Organization organization = organizationRepository.selectByName(importPersonWarCaseParam.getOrganizationName());
                    if (organization == null) {
                        error.append("组织【" + importPersonWarCaseParam.getOrganizationName() + "】不存在;");
                        continue;
                    }

                    PersonWarCase personWarCase = new PersonWarCase();
                    BeanUtils.copyProperties(importPersonWarCaseParam, personWarCase);
                    personWarCase.setId(IdGenerator.SNOW.generate());
                    personWarCase.setIsDelete(false);
                    personWarCase.setIsDisable(false);
                    personWarCase.setCombatPower((int) (Math.random() * 40 + 60));
                    personWarCaseRepository.create(personWarCase);

//                     多组织架构
                    PersonOrganizationMp mpWarCase = new PersonOrganizationMp();
                    mpWarCase.setId(IdGenerator.SNOW.generate());
                    mpWarCase.setPersonId(personWarCase.getId());
                    mpWarCase.setOrganizationId(organization.getId());
                    if (!personOrganizationMpRepository.create(mpWarCase)) {
                        error.append("导入失败;");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (!StringUtils.isEmpty(error.toString())) {
            throw new BizException(error.toString());
        }
    }

    @Override
    public void setPathByPersonWar() {

    }


    //获得两个日期之间所有的月
    public List<String> getBetweenMonth(LocalDate start, LocalDate end) {
        List<String> result = new ArrayList<>();

        int startYear = start.getYear();
        int startMonth = start.getMonthValue();
        int endYear = end.getYear();
        int endMonth = end.getMonthValue();

        while (startYear < endYear || (startYear == endYear && startMonth <= endMonth)) {
            result.add(startYear + "-" + (startMonth < 10 ? "0" + startMonth : startMonth));

            if (startMonth == 12) {
                startYear++;
                startMonth = 1;
            } else {
                startMonth++;
            }
        }
        return result;
    }
}



